use bcrypt::BcryptError;
use entity::meeting_room::DbErr;

use self::auth_check::AuthCheckFailureError;

pub mod auth;
pub mod auth_check;

pub struct PwdEncoder;

impl PwdEncoder {
    pub fn verify(
        raw: impl AsRef<str>,
        encoded: impl AsRef<str>,
    ) -> Result<bool, bcrypt::BcryptError> {
        bcrypt::verify(raw.as_ref(), encoded.as_ref())
    }
    pub fn encode(raw: impl AsRef<str>) -> Result<String, bcrypt::BcryptError> {
        bcrypt::hash(raw.as_ref(), bcrypt::DEFAULT_COST)
    }
}

err_utils::error_gen! {
    pub UserNotFound=>"用户存在"
}

err_utils::error_gen! {
    pub PasswordError=>"密码错误"
}

err_utils::error_gen! {
    pub UserVerifyError{
        UserNotFound=UserNotFound
        PwdError=PasswordError
        Bcrypt=BcryptError
        AuthCheckFailure=AuthCheckFailureError
        Db=DbErr
    }
}
